package com.atguigu;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Test4 {

	public static void main(String[] args) {
		final Note1 note = new Note1();
		final Lock l = new ReentrantLock();
		final Condition con1 = l.newCondition();
		final Condition con2 = l.newCondition();
		
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				l.lock();
				try {
					for (int i = 0; i < 26; i++) {
						
						con2.signal();
						note.printNum();
						con1.await();
					}
				} catch (Exception e) {
				}finally{
					l.unlock();
				}
			}
		}, "AA").start();
		
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				l.lock();
				try {
					for (int i = 0; i < 26; i++) {
						
						con1.signal();
						note.printLet();
						con2.await();
					}
				} catch (Exception e) {
				}finally{
					l.unlock();
				}
			}
		}, "BB").start();
		
		
	}
	
}


class Note1{

	private int num = 0;
	private int i = -1;
	public void printNum(){
		System.out.print(++ num);
		System.out.print(++ num);
		
	}
	
	public void printLet(){
		
		System.out.print((char)('A' + ++i));
		
	}
	
	
	
}

